package com.example.administrator.testproject;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import java.util.ArrayList;
import java.util.List;

/**
 * Created by shawei on 2017/11/24.
 */

public class EducationHistoeySchoolAdapter extends PagerAdapter {
    private Context mContext;
    private List<String> inforListData;

    public EducationHistoeySchoolAdapter(Context mContext) {
        this.mContext = mContext;
        inforListData = new ArrayList<>();
    }

    public void setData(List<String> listData) {
        if (listData != null) {
            inforListData.clear();
            inforListData.addAll(listData);
            notifyDataSetChanged();
        }
    }

    /**
     * 返回多少page
     */
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    /**
     * view滑动到一半时是否创建新的view
     * true:表示不去创建，使用缓存；false:去重新创建
     */
    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    /**
     * 类似于BaseAdapter的getView方法
     */
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_history_vg, null);
        TextView text = (TextView) view.findViewById(R.id.text);
        text.setText(inforListData.get(position % inforListData.size()));
        ImageView imageView=(ImageView)view.findViewById(R.id.imageView);
        container.addView(view);
        return view;
    }

    /**
     * @param position:当前需要销毁第几个page
     * @param object:当前需要销毁的page
     */
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
//            super.destroyItem(container, position, object);
        container.removeView((View) object);
    }
}
